﻿@model IEnumerable<DistributeTransaction.Models.Product>
@{
    ViewBag.Title = "Products Information";
    Layout = "~/Views/Shared/_Layout.cshtml";
    var grid = new WebGrid(source: Model);
}
<h2>
    Products Information</h2>
@using (Html.BeginForm())
{
    <div>
        <table style="table-layout: auto;" cellpadding="0" cellspacing="0" border="0" class="noborder">
            <tr>
                <td class="noborder" align="right">
                    Find by name: @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
                </td>
                <td class="noborder" align="left">
                    <input type="submit" value="Search" id="find"/>
                </td>
                @if (User.Identity.IsAuthenticated)
                {
                <td class="noborder">
                    <input type="submit" name="command" id="cart" value="Add To ShoppingCart" disabled="disabled" />
                </td>
                <td class="noborder">
                    <input type="submit" name="command" id="watchlist" value="Add To WatchList" disabled="disabled" />
                </td>
                }
                else
                {
                    <td class="noborder">
                        <span class="summary-label">Login with your account to access shopping cart and watch list.</span>
                    </td>
                }
                <td class="noborder">
                    <span class="summary-label">@ViewBag.Summary</span>
                </td>
            </tr>
        </table>
    </div>
    <fieldset>
        <legend></legend>
        @grid.GetHtmlWithSelectAllCheckBox(
                tableStyle: "grid",
                checkBoxValue: "ProductID",
                columns: grid.Columns(
                         grid.Column(columnName: "ProductID", header: "ID", style: "text-align-left"),
                         grid.Column(format: item => new HelperResult(writer => writer.Write("<image src='" + Url.Action("Image", "Product", new { id = item.CategoryID }) + "' alt='Category Logo' style='width:25px;height:20px;'/>"))),
                         grid.Column(columnName: "CategoryName", header: "Category", style: "text-align-center"),
                         grid.Column(columnName: "ProductName", header: "Product Name", style: "text-align-center"),
                         grid.Column(columnName: "UnitPrice", header: "Price", style: "text-align-right", format: (item) => string.Format("{0:C}", item.UnitPrice)),
                         grid.Column(columnName: "QuantityPerUnit", header: "Decription", style: "text-align-center"),
                         grid.Column(columnName: "CompanyName", header: "Manufacturer", style: "text-align-center"),
                         grid.Column(columnName: "MadeIn", header: "MadeIn", style: "text-align-center")
               ))
    </fieldset>
    <script type="text/javascript" language="javascript">
        $("#allCheckBox").live('change', function () {
            if ($(this).attr("checked") || $(this).attr("indeterminate")) {
                $("#cart").removeAttr("disabled");
                $("#watchlist").removeAttr("disabled");
            } else {
                $("#cart").attr("disabled", "disabled");
                $("#watchlist").attr("disabled", "disabled");
            }
        });
        $('.singleCheckBox').live('change', function () {
            if ($("#allCheckBox").attr("checked") || $(this).attr("checked")) {
                $("#cart").removeAttr("disabled");
                $("#watchlist").removeAttr("disabled");
            } else {
                $("#cart").attr("disabled", "disabled");
                $("#watchlist").attr("disabled", "disabled");
            }
        });
        $('#SearchString').live('keypress', function (e) {
            if (e.which == 13)
                $("#find").click();
        });
        $('#SearchString').live('input paste', function () {
            if ($('#SearchString').attr("value").length == 0) {
                $("#find").attr("value", "Clear");
            }
            else {
                $("#find").attr("value", "Search");
            }
        });
    </script>
}